/**
 * 
 */
package com.res.simulator.plugins;

import java.io.IOException;

import org.springframework.stereotype.Component;

import com.res.system.utils.SimulatorUtilities;
import com.res.system.utils.SimulatorUtilities.ConfigData;
import com.sip.comserver.communication.CommunicationMessage;
import com.sip.comserver.communication.client.CommunicationClient;

/**
 * @author Dhanushka Ariyasingha.
 * 
 */
@Component
public class MessageCommunicationClientPlugin {



	
	public CommunicationMessage invoke(final CommunicationMessage message) throws IOException,
			ClassNotFoundException {

	
	
		final String serverAddress=SimulatorUtilities.getConfigData(ConfigData.SERVER_ADDRESS);
	    final String port=SimulatorUtilities.getConfigData(ConfigData.SERVER_PORT);
	    int portValue=Integer.parseInt(port);
	    
	    System.out.println("======="+serverAddress+"--"+port);
		// parameters.
		final CommunicationClient client = new CommunicationClient(serverAddress, portValue);

		client.send(message);

		final CommunicationMessage outputMessage = client.read();

		System.out.println("Reading output message from client side.");
		//System.out.println(outputMessage.getMessageBody());
		
		return outputMessage;


	}

}
